home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -websites- / wirenet / files / updatewirenet.lzx / Updates / Connect next >
Text File  |  2008-02-05  |  6KB  |  194 lines

  1. /* $VER: Connect 1.4  (07.06.96)        */
  2. /* Connects your Amiga to the Internet */
  3. /*
  4.     Name
  5.         Connect
  6.  
  7.     Usage
  8.         Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]
  9.  
  10.     Options
  11.         None:       Connects to Internet
  12.         MAIL:       Connects to Internet and fetches mail
  13.         NEWS:       Connects to Internet and fetches news and mail
  14.         AUTOMAIL:   Connects to Internet, fetches mail and disconnects
  15.         AUTONEWS:   Connects to Internet, fetches news and mail and disconnects
  16.         OFF:        Disconnects from Internet
  17.         AUTOOFF:    Disconnects from Internet after waiting for news and mail to finish
  18.  
  19. */
  20.  
  21. /* These are specific to your setup */
  22.  
  23. DevName    = 'DEVS:Networks/ppp.device'                             /* Your network device */
  24. DevUnit    = 0                                                      /* its unit number */
  25. Interface  = 'ppp'||DevUnit                                         /* Interface name */
  26. BeforeCon  = ''                                                     /* Commands to be executed */
  27. AfterCon   = ''                                                     /* before and after */
  28. BeforeDis  = ''                                                     /* connection and */
  29. AfterDis   = ''                                                     /* disconnection */
  30.  
  31. /* Don't change anything below here */
  32.  
  33. if ~show('L','rexxdossupport.library') then
  34.     call addlib('rexxdossupport.library',0,-30)
  35.  
  36. BinPath    = 'AmiTCP:bin/'                                          /* Paths to AmiTCP commands */
  37. ThorPath   = GetVar('Thor/ThorPath')
  38. StartNet   = BinPath||'StartNet'
  39. ifconfig   = BinPath||'ifconfig'
  40. route      = BinPath||'route'
  41. online     = BinPath||'online'
  42. offline    = BinPath||'offline'
  43. resolve    = BinPath||'resolve'
  44. SendEvents = BinPath||'SendEvents'
  45. GetMail    = BinPath||'Fetch Mail'
  46. GetNews    = BinPath||'Fetch All'
  47. LogPath    = 'UUSpool:Connect.log'
  48. SendProc   = ThorPath||'bin/SendTCP'                                /* CLI process names for news and mail */
  49. GetProc    = ThorPath||'bin/GetTCP'
  50. Unbatch    = BinPath||'ParseThor'
  51.  
  52. options results
  53. address command
  54. arg opt
  55.  
  56. /* Main routine */
  57.  
  58. select
  59.     when opt = '' then call Connect
  60.     when opt = 'MAIL' then do
  61.         call Connect
  62.         call DoMail
  63.         end
  64.     when opt = 'NEWS' then do
  65.         call Connect
  66.         call DoNews
  67.         end
  68.     when opt = 'AUTOMAIL' then do
  69.         call Connect
  70.         call DoMail
  71.         call Auto
  72.         call Disconnect
  73.         end
  74.     when opt = 'AUTONEWS' then do
  75.         call Connect
  76.         call DoNews
  77.         call Auto
  78.         call Disconnect
  79.         end
  80.     when opt = 'OFF' then call Disconnect
  81.     when opt = 'AUTOOFF' then do
  82.         call Auto
  83.         call Disconnect
  84.         end
  85.     otherwise call BadArgs
  86.     end
  87.  
  88. exit
  89.  
  90. /* Procedures */
  91.  
  92. Connect:                                                        /* Establish connection */
  93.     BeforeCon
  94.     StartNet
  95.     unsetenv ppp0IPLocal
  96.     unsetenv ppp0IPRemote
  97.     online DevName DevUnit
  98.     if RC > 0 then call ConnectionFailed
  99.     ifconfig 'lo0 localhost'
  100.     ifconfig Interface '$ppp0IPLocal $ppp0IPRemote'
  101.     route 'add default $ppp0IPRemote'
  102.     call WriteLog('Connection made')
  103.     'SetEnv NetState Online'
  104.     'run >NIL:' SendEvents
  105.     AfterCon
  106.     Wait 3
  107.     return
  108.  
  109. Disconnect:                                                     /* Break connection */
  110.     BeforeDis
  111.     ifconfig interface 'down'
  112.     offline DevName DevUnit
  113.     route 'delete >NIL: $ppp0IPLocal'
  114.     route 'delete >NIL: default'
  115.     call WriteLog('Connection closed')
  116.     'SetEnv NetState Offline'
  117.     Unbatch
  118.     AfterDis
  119.     return
  120.  
  121. DoMail:
  122.     'run >NIL:' GetMail                                             /* Start mail download */
  123.     call WriteLog('Mail download started')
  124.     return
  125.  
  126. DoNews:
  127.     'Run >NIL:' GetNews                                             /* Start mail and news download */
  128.     call WriteLog('News download started')
  129.     return
  130.  
  131. Auto:
  132.     say 'Waiting for news/mail to finish'                           /* Wait for mail and news processes to stop */
  133.     call WaitToEnd(SendProc GetProc)
  134.     Wait 2
  135.     call WaitToEnd(SendProc GetProc 'ncftp')
  136.     return
  137.  
  138. BadArgs:                                                            /* Give usage information */
  139.     say
  140.     say 'Usage: Connect [MAIL|NEWS|AUTOMAIL|AUTONEWS|OFF|AUTOOFF]'
  141.     say
  142.     say '       None:       Connects to Internet'
  143.     say '       MAIL:       Connects to Internet and fetches mail'
  144.     say '       NEWS:       Connects to Internet and fetches news and mail'
  145.     say '       AUTOMAIL    Connects to Internet, fetches mail and disconnects'
  146.     say '       AUTONEWS:   Connects to Internet, fetches news and mail and disconnects'
  147.     say '       OFF:        Disconnects from Internet'
  148.     say '       AUTOOFF:    Disconnects from Internet after waiting for news and mail to finish'
  149.     say
  150.     exit
  151.  
  152. WriteLog: procedure expose LogPath                                  /* Write line in logfile */
  153.     parse arg msg
  154.     LogEntry = left(date('W'),3) date() time() msg
  155.     say LogEntry
  156.     if ~open(log,LogPath,'A') then do
  157.         if ~open(log,LogPath,'W') then return
  158.         end
  159.     call writeln(log,LogEntry)
  160.     call close(log)
  161.     return
  162.  
  163. WaitToEnd: procedure                                                /* Wait for the specified process to finish */
  164.     parse arg Processes
  165.  
  166.     procs = words(Processes)
  167.     do i = 1 to procs
  168.         parse var Processes Process.i Processes
  169.         end
  170.  
  171.     do until Busy = FALSE
  172.         Busy = FALSE
  173.         do i = 1 to procs
  174.             'Status >NIL: com='Process.i
  175.             if RC = 0 then do
  176.                 Busy = TRUE
  177.                 Wait 5
  178.                 end
  179.             end
  180.         end
  181.     return
  182.  
  183. ConnectionFailed:
  184.     call WriteLog('Connection attempt failed')                      /* Report connection failure */
  185.     Ouch('Your internet connection has failed')
  186.     return
  187.  
  188. Ouch:
  189.     parse arg ErrMsg
  190.     say(ErrMsg)
  191.     exit
  192.     return
  193.  
  194.